package com.ynu.springbootappdemo.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ynu.springbootappdemo.common.entity.BaseEntity;
import lombok.*;

import javax.persistence.*;
import java.util.List;

@Entity
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class Categories extends BaseEntity {

    @Column
    private String name;

    @Column
    private Integer layer;

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id") // 指定外键列的名称
    private Categories parent;

    @OneToMany(mappedBy = "categories",
            fetch = FetchType.EAGER,
            orphanRemoval = true,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("categories")
    private List<CateGoods> cateGoods;
}

